<!DOCTYPE html>
<html class="x-admin-sm" xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/extras/spring-security"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <meta charset="UTF-8">
    <title>自习室列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,room-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="stylesheet" th:href="@{/css/font.css}">
    <link rel="stylesheet" th:href="@{/css/xadmin.css}">
    <script th:src="@{/lib/layui/layui.js}" charset="utf-8"></script>
    <script type="text/javascript" th:src="@{/js/xadmin.js}"></script>
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->

</head>
<body>

<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header" th:if="${user.role} eq '管理员'">
                    <button class="layui-btn" onclick="xadmin.open('添加','/admin/toAddRoom')"><i
                            class="layui-icon"></i>添加自习室
                    </button>
                </div>
                <div class="layui-card-body layui-table-body layui-table-main">
                    <table class="layui-table layui-form">
                        <thead>
                        <tr>
                            <th>序号</th>
                            <th>ID</th>
                            <th>自习室名称</th>
                            <th>开放说明</th>
                            <th>座位数量</th>
                            <th>开放时间</th>
                            <th style="text-align: center">操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        <div>
                            <tr th:each="room,userStat:${roomList}">
                                <td style="text-align: center" th:text="${userStat.count}"></td>
                                <td style="text-align: center" th:text="${room.id}"></td>
                                <td style="text-align: center" th:text="${room.name}"></td>
                                <td style="text-align: center" th:text="${room.openDesc}"></td>
                                <td style="text-align: center" th:text="${room.seatNum}"></td>
                                <td style="text-align: center" th:text="${room.openTimeRange}"></td>
                                <td class="td-manage" style="text-align: center">
                                    <button th:onclick="xadmin.open('详情',[['/room/getRoomInfo?id='+${room.id}]])" type="button" class="layui-btn layui-btn-normal layui-btn-sm"><span th:text="${user.role} eq '管理员' ? '查看' : '选座'"></span></span></button>
                                    <button th:if="${user.role} eq '管理员'" th:onclick="xadmin.open('编辑',[['/admin/toEditRoom?id='+${room.id}]])" type="button" class="layui-btn layui-btn-sm">编辑</button>
                                    <button th:if="${user.role} eq '管理员'" th:onclick="member_del(this,[[${room.id}]])" type="button" class="layui-btn layui-btn-danger layui-btn-sm">删除</button>
                                </td>
                            </tr>
                        </div>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script>
    /*用户-删除*/
    function member_del(obj, id) {
        layer.confirm('确认要删除吗？', function (index) {
            console.log(id)
            $(obj).parents("tr").remove();
            layer.msg('已删除!', {icon: 1, time: 1000});
            //发异步删除数据
            $.ajax({
                url: "/admin/deleteRoom",
                type: "POST",
                data: {"id": id},
                dataType: 'json',
                success: function (result) {
                },
            });

        });
    }


    function delAll(argument) {
        var ids = [];

        // 获取选中的id
        $('tbody input').each(function (index, el) {
            if ($(this).prop('checked')) {
                ids.push($(this).val())
            }
        });

        layer.confirm('确认要删除吗？' + ids.toString(), function (index) {
            //捉到所有被选中的，发异步进行删除
            layer.msg('删除成功', {icon: 1});
            $(".layui-form-checked").not('.header').parents('tr').remove();
        });
    }
</script>
</html>
